<!DOCTYPE html>
<html lang="zh-CN">





<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="https://img2.jimu98.cn/blog/20200729222712.png">
  <link rel="icon" type="image/png" href="https://img2.jimu98.cn/blog/20200729222712.png">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="你会的越多,你不会的越多,我是积木,互联网的一只小菜鸡">
  <meta name="author" content="积木">
  <meta name="keywords" content="积木,jimu98,java,后端,jimu">
  <title>【项目创建流程】集成Redis缓存 - 积木 | 互联网的一只小菜鸡</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/github-gist.min.css" />
  

  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_yg9cfy8wd6.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_pjno9b9zyxs.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/js/utils.js" ></script>
  <script data-ad-client="ca-pub-2806771379080352" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<meta name="generator" content="Hexo 4.2.1"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>jimu98</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/list/">
                <i class="iconfont icon-bookmark-fill"></i>
                导航
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/links/">
                <i class="iconfont icon-link-fill"></i>
                友链
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="view intro-2" id="background" parallax=true
         style="background: url('https://img2.jimu98.cn/blog/20200729222405.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container text-center white-text fadeInUp">
            <span class="h2" id="subtitle">
              
            </span>

            
              
  <div class="mt-3 post-meta">
    <i class="iconfont icon-date-fill" aria-hidden="true"></i>
    <time datetime="2020-07-08 16:17">
      2020年7月8日 下午
    </time>
  </div>


<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      877 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      12
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <div class="post-content mx-auto" id="post">
            
            <article class="markdown-body">
              <h1 id="【项目创建流程】集成Redis缓存"><a href="#【项目创建流程】集成Redis缓存" class="headerlink" title="【项目创建流程】集成Redis缓存"></a>【项目创建流程】集成Redis缓存</h1><h2 id="一、简介"><a href="#一、简介" class="headerlink" title="一、简介"></a>一、简介</h2><h3 id="1、场景"><a href="#1、场景" class="headerlink" title="1、场景"></a>1、场景</h3><p>由于首页数据变化不是很频繁，而且首页访问量相对较大，所以我们有必要把首页数据缓存到redis中，减少数据库压力和提高访问速度。</p>
<h3 id="2、RedisTemplate"><a href="#2、RedisTemplate" class="headerlink" title="2、RedisTemplate"></a>2、RedisTemplate</h3><p>Jedis是Redis官方推荐的面向Java的操作Redis的客户端，而RedisTemplate是Spring Data Redis中对Jedis api的高度封装。</p>
<p>Spring Data Redis是spring大家族的一部分，提供了在srping应用中通过简单的配置访问redis服务，对reids底层开发包(Jedis,  JRedis, and RJC)进行了高度封装，RedisTemplate提供了redis各种操作、异常处理及序列化功能，支持发布订阅，并对spring cache进行了实现。</p>
<h2 id="二、引入redis"><a href="#二、引入redis" class="headerlink" title="二、引入redis"></a>二、引入redis</h2><h3 id="1、项目中集成redis"><a href="#1、项目中集成redis" class="headerlink" title="1、项目中集成redis"></a>1、项目中集成redis</h3><p>common父模块中添加redis依赖，Spring Boot 2.0以上默认通过commons-pool2连接池连接redis</p>
<pre><code class="hljs xml"><span class="hljs-comment">&lt;!-- spring boot redis缓存引入 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-data-redis<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-comment">&lt;!-- lecttuce 缓存连接池--&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.commons<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>commons-pool2<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span></code></pre>

<h3 id="2、添加redis连接配置"><a href="#2、添加redis连接配置" class="headerlink" title="2、添加redis连接配置"></a>2、添加redis连接配置</h3><p>service_cms 和 service_edu 的 application.yml 中添加如下配置</p>
<pre><code class="hljs yaml"><span class="hljs-attr">spring:</span> 
  <span class="hljs-attr">redis:</span>
    <span class="hljs-attr">host:</span> <span class="hljs-number">192.168</span><span class="hljs-number">.100</span><span class="hljs-number">.100</span>
    <span class="hljs-attr">port:</span> <span class="hljs-number">6379</span>
    <span class="hljs-attr">database:</span> <span class="hljs-number">0</span>
    <span class="hljs-attr">password:</span> <span class="hljs-number">123456</span> <span class="hljs-comment">#默认为空</span>
    <span class="hljs-attr">lettuce:</span>
      <span class="hljs-attr">pool:</span>
        <span class="hljs-attr">max-active:</span> <span class="hljs-number">20</span>  <span class="hljs-comment">#最大连接数，负值表示没有限制，默认8</span>
        <span class="hljs-attr">max-wait:</span> <span class="hljs-number">-1</span>    <span class="hljs-comment">#最大阻塞等待时间，负值表示没限制，默认-1</span>
        <span class="hljs-attr">max-idle:</span> <span class="hljs-number">8</span>     <span class="hljs-comment">#最大空闲连接，默认8</span>
        <span class="hljs-attr">min-idle:</span> <span class="hljs-number">0</span>     <span class="hljs-comment">#最小空闲连接，默认0</span></code></pre>

<h3 id="3、配置Redis"><a href="#3、配置Redis" class="headerlink" title="3、配置Redis"></a>3、配置Redis</h3><p>service-base添加RedisConfig</p>
<pre><code class="hljs haxe"><span class="hljs-keyword">package</span> com.atguigu.guli.service.base.config;

<span class="hljs-comment">/**</span>
<span class="hljs-comment"> * 我们自定义一个 RedisTemplate，设置序列化器，这样我们可以很方便的操作实例对象。</span>
<span class="hljs-comment"> * 否则redis自动使用对象的jdk序列化</span>
<span class="hljs-comment"> */</span>
@Configuration
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">RedisConfig</span> </span>&#123;

    @Bean
    <span class="hljs-keyword">public</span> RedisTemplate&lt;<span class="hljs-keyword">String</span>, Serializable&gt; redisTemplate(LettuceConnectionFactory connectionFactory) &#123;
        RedisTemplate&lt;<span class="hljs-keyword">String</span>, Serializable&gt; redisTemplate = <span class="hljs-keyword">new</span> <span class="hljs-type">RedisTemplate</span>&lt;&gt;();
        redisTemplate.setKeySerializer(<span class="hljs-keyword">new</span> <span class="hljs-type">StringRedisSerializer</span>());<span class="hljs-comment">//key序列化方式</span>
        redisTemplate.setValueSerializer(<span class="hljs-keyword">new</span> <span class="hljs-type">GenericJackson2JsonRedisSerializer</span>());<span class="hljs-comment">//value序列化</span>
        redisTemplate.setConnectionFactory(connectionFactory);
        
        <span class="hljs-keyword">return</span> redisTemplate;
    &#125;
&#125;</code></pre>



<h2 id="三、测试redisTemplate"><a href="#三、测试redisTemplate" class="headerlink" title="三、测试redisTemplate"></a>三、测试redisTemplate</h2><h3 id="1、测试redis数据存储"><a href="#1、测试redis数据存储" class="headerlink" title="1、测试redis数据存储"></a>1、测试redis数据存储</h3><p>ApiAdController中添加下面的方法进行测试</p>
<pre><code class="hljs kotlin"><span class="hljs-meta">@Autowired</span>
<span class="hljs-keyword">private</span> RedisTemplate redisTemplate;

<span class="hljs-meta">@PostMapping(<span class="hljs-meta-string">"save-test"</span>)</span>
<span class="hljs-keyword">public</span> R saveAd(<span class="hljs-meta">@RequestBody</span> Ad ad)&#123;
    <span class="hljs-comment">//redisTemplate.opsForValue().set("ad1", ad);</span>
    redisTemplate.opsForValue().<span class="hljs-keyword">set</span>(<span class="hljs-string">"index::ad"</span>, ad);
    <span class="hljs-keyword">return</span> R.ok();
&#125;

<span class="hljs-meta">@GetMapping(<span class="hljs-meta-string">"get-test/&#123;key&#125;"</span>)</span>
<span class="hljs-keyword">public</span> R getAd(<span class="hljs-meta">@PathVariable</span> String key)&#123;
    Ad ad = (Ad)redisTemplate.opsForValue().<span class="hljs-keyword">get</span>(key);
    <span class="hljs-keyword">return</span> R.ok().<span class="hljs-keyword">data</span>(<span class="hljs-string">"ad"</span>, ad);
&#125;

<span class="hljs-meta">@DeleteMapping(<span class="hljs-meta-string">"remove-test/&#123;key&#125;"</span>)</span>
<span class="hljs-keyword">public</span> R removeAd(<span class="hljs-meta">@PathVariable</span> String key)&#123;
    <span class="hljs-built_in">Boolean</span> delete = redisTemplate.delete(key);
    System.<span class="hljs-keyword">out</span>.println(delete);<span class="hljs-comment">//是否删除成功</span>
    <span class="hljs-built_in">Boolean</span> hasKey = redisTemplate.hasKey(key);
    System.<span class="hljs-keyword">out</span>.println(hasKey);<span class="hljs-comment">//key是否存在</span>
    <span class="hljs-keyword">return</span> R.ok();
&#125;</code></pre>

<h3 id="2、常用方法"><a href="#2、常用方法" class="headerlink" title="2、常用方法"></a>2、常用方法</h3><p>redisTemplate提供了以下几种存储数据的方法</p>
<pre><code class="hljs gcode">redisTemplate.opsForValue<span class="hljs-comment">()</span>; <span class="hljs-comment">//操作字符串</span>
redisTemplate.opsForHash<span class="hljs-comment">()</span>; <span class="hljs-comment">//操作hash</span>
redisTemplate.opsForList<span class="hljs-comment">()</span>; <span class="hljs-comment">//操作list</span>
redisTemplate.opsForSet<span class="hljs-comment">()</span>; <span class="hljs-comment">//操作set</span>
redisTemplate.opsForZSet<span class="hljs-comment">()</span>; <span class="hljs-comment">//操作有序set</span></code></pre>

<h2 id="四、使用缓存注解"><a href="#四、使用缓存注解" class="headerlink" title="四、使用缓存注解"></a>四、使用缓存注解</h2><h3 id="1、修改Redis配置类"><a href="#1、修改Redis配置类" class="headerlink" title="1、修改Redis配置类"></a>1、修改Redis配置类</h3><p>配置类上添加注解</p>
<pre><code class="hljs aspectj"><span class="hljs-meta">@EnableCaching</span></code></pre>

<p>添加bean配置</p>
<pre><code class="hljs reasonml">@Bean
public CacheManager cache<span class="hljs-constructor">Manager(LettuceConnectionFactory <span class="hljs-params">connectionFactory</span>)</span> &#123;
    
    RedisCacheConfiguration config = <span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">RedisCacheConfiguration</span>.</span></span>default<span class="hljs-constructor">CacheConfig()</span>
        <span class="hljs-comment">//过期时间600秒</span>
        .entry<span class="hljs-constructor">Ttl(Duration.<span class="hljs-params">ofSeconds</span>(600)</span>) 
        <span class="hljs-comment">// 配置序列化</span>
        .serialize<span class="hljs-constructor">KeysWith(RedisSerializationContext.SerializationPair.<span class="hljs-params">fromSerializer</span>(<span class="hljs-params">new</span> StringRedisSerializer()</span>))
        .serialize<span class="hljs-constructor">ValuesWith(RedisSerializationContext.SerializationPair.<span class="hljs-params">fromSerializer</span>(<span class="hljs-params">new</span> GenericJackson2JsonRedisSerializer()</span>))
        .disable<span class="hljs-constructor">CachingNullValues()</span>;

    RedisCacheManager cacheManager = <span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">RedisCacheManager</span>.</span></span>builder(connectionFactory)
        .cache<span class="hljs-constructor">Defaults(<span class="hljs-params">config</span>)</span>
        .build<span class="hljs-literal">()</span>;
    return cacheManager;
&#125;</code></pre>

<h3 id="2、添加缓存注解"><a href="#2、添加缓存注解" class="headerlink" title="2、添加缓存注解"></a>2、添加缓存注解</h3><p>@Cacheable(value = “xxx”, key = “‘xxx’”)：标注在方法上，对方法返回结果进行缓存。下次请求时，如果缓存存在，则直接读取缓存数据返回；如果缓存不存在，则执行方法，并把返回的结果存入缓存中。一般用在查询方法上。</p>
<p>service_cms：AdServiceImpl</p>
<pre><code class="hljs less"><span class="hljs-variable">@Cacheable</span>(value = <span class="hljs-string">"index"</span>, key = <span class="hljs-string">"'selectByAdTypeId'"</span>)
<span class="hljs-variable">@Override</span>
public List&lt;Ad&gt; selectByAdTypeId(String adTypeId) &#123;</code></pre>

<p>service_edu：CourseServiceImpl</p>
<pre><code class="hljs less"><span class="hljs-variable">@Cacheable</span>(value = <span class="hljs-string">"index"</span>, key = <span class="hljs-string">"'selectHotCourse'"</span>)
<span class="hljs-variable">@Override</span>
public List&lt;Course&gt; selectHotCourse() &#123;</code></pre>

<p>service_edu：TeacherServiceImpl</p>
<pre><code class="hljs less"><span class="hljs-variable">@Cacheable</span>(value = <span class="hljs-string">"index"</span>, key = <span class="hljs-string">"'selectHotTeacher'"</span>)
<span class="hljs-variable">@Override</span>
public List&lt;Teacher&gt; selectHotTeacher() &#123;</code></pre>
            </article>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/%E9%A1%B9%E7%9B%AE%E6%9E%84%E5%BB%BA/">项目构建</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/SpringCloud/">SpringCloud</a>
                    
                      <a class="hover-with-bg" href="/tags/%E5%BE%AE%E6%9C%8D%E5%8A%A1/">微服务</a>
                    
                      <a class="hover-with-bg" href="/tags/Redis/">Redis</a>
                    
                      <a class="hover-with-bg" href="/tags/bean/">bean</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" target="_blank" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！</p>
              
              
                <div class="post-prevnext row">
                  <div class="post-prev col-6">
                    
                    
                      <a href="/2020/07/08/goujian/12.Gateway%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%BD%91%E5%85%B3/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">【项目创建流程】Gateway微服务网关</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </div>
                  <div class="post-next col-6">
                    
                    
                      <a href="/2020/07/08/goujian/10.Sentinel%E4%BB%8B%E7%BB%8D%E5%92%8C%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/">
                        <span class="hidden-mobile">【项目创建流程】Sentinel介绍和环境搭建</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </div>
                </div>
              
            </div>

            
              <!-- Comments -->
              <div class="comments" id="comments">
                
                
  <div id="vcomments"></div>
  <script type="text/javascript">
    function loadValine() {
      addScript('https://cdn.staticfile.org/valine/1.4.14/Valine.min.js', function () {
        new Valine({
          el: "#vcomments",
          app_id: "NFojgagn3zsFUjT0FGVVHUTM-gzGzoHsz",
          app_key: "9R1L32c7WEvSGSP48NAnfStY",
          placeholder: "说点什么",
          path: window.location.pathname,
          avatar: "retro",
          meta: ["nick","mail","link"],
          pageSize: "10",
          lang: "zh-CN",
          highlight: false,
          recordIP: true,
          serverURLs: "https://nfojgagn.lc-cn-n1-shared.com",
        });
      });
    }
    createObserver(loadValine, 'vcomments');
  </script>
  <noscript>Please enable JavaScript to view the <a href="https://valine.js.org" target="_blank" rel="nofollow noopener noopener">comments
      powered by Valine.</a></noscript>


              </div>
            
          </div>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  

  <footer class="mt-5">
  <div class="text-center py-3">
  <p id="hitokoto">:D 获取中...</p>
<script>
  fetch('https://v1.hitokoto.cn')
    .then(response => response.json())
    .then(data => {
      const hitokoto = document.getElementById('hitokoto')
      hitokoto.innerText = data.hitokoto
      })
      .catch(console.error)
</script>
   <div>
  <span id="timeDate">载入天数...</span>
  <span id="times">载入时分秒...</span>
  <script>
  var now = new Date();
  function createtime(){
      var grt= new Date("07/18/2020 18:00:00");//此处修改你的建站时间或者网站上线时间
      now.setTime(now.getTime()+250);
      days = (now - grt ) / 1000 / 60 / 60 / 24;
      dnum = Math.floor(days);
      hours = (now - grt ) / 1000 / 60 / 60 - (24 * dnum);
      hnum = Math.floor(hours);
      if(String(hnum).length ==1 ){
          hnum = "0" + hnum;
      }
      minutes = (now - grt ) / 1000 /60 - (24 * 60 * dnum) - (60 * hnum);
      mnum = Math.floor(minutes);
      if(String(mnum).length ==1 ){
                mnum = "0" + mnum;
      }
      seconds = (now - grt ) / 1000 - (24 * 60 * 60 * dnum) - (60 * 60 * hnum) - (60 * mnum);
      snum = Math.round(seconds);
      if(String(snum).length ==1 ){
                snum = "0" + snum;
      }
      document.getElementById("timeDate").innerHTML = "本站安全运行&nbsp"+dnum+"&nbsp天";
      document.getElementById("times").innerHTML = hnum + "&nbsp小时&nbsp" + mnum + "&nbsp分&nbsp" + snum + "&nbsp秒";
  }
  setInterval("createtime()",250);
  </script>
</div>
    <div>
      &copy;2019 - 2020 By Jimu98
    </div>
    

    
  <!-- 备案信息 -->
  <div class="beian">
		
          <img src="/img/police_beian.png" srcset="/img/loading.gif" alt="police-icon" />
        
    <a href="http://beian.miit.gov.cn/" target="_blank"
       rel="nofollow noopener">冀ICP备19035627号</a>
    
  </div>


    
      <!-- cnzz Analytics Icon -->
      <span id="cnzz_stat_icon_1278280985" style="display: none"></span>
    
  </div>

</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/main.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/lazyload.js" ></script>
  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>







  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: 'article.markdown-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "【项目创建流程】集成Redis缓存&nbsp;",
      ],
      cursorChar: "|",
      typeSpeed: 95,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>







  
  
    <script>
      !function (e, t, a) {
        function r() {
          for (var e = 0; e < s.length; e++) s[e].alpha <= 0 ? (t.body.removeChild(s[e].el), s.splice(e, 1)) : (s[e].y--, s[e].scale += .004, s[e].alpha -= .013, s[e].el.style.cssText = "left:" + s[e].x + "px;top:" + s[e].y + "px;opacity:" + s[e].alpha + ";transform:scale(" + s[e].scale + "," + s[e].scale + ") rotate(45deg);background:" + s[e].color + ";z-index:99999");
          requestAnimationFrame(r)
        }

        function n() {
          var t = "function" == typeof e.onclick && e.onclick;
          e.onclick = function (e) {
            t && t(), o(e)
          }
        }

        function o(e) {
          var a = t.createElement("div");
          a.className = "heart", s.push({
            el: a,
            x: e.clientX - 5,
            y: e.clientY - 5,
            scale: 1,
            alpha: 1,
            color: c()
          }), t.body.appendChild(a)
        }

        function i(e) {
          var a = t.createElement("style");
          a.type = "text/css";
          try {
            a.appendChild(t.createTextNode(e))
          } catch (t) {
            a.styleSheet.cssText = e
          }
          t.getElementsByTagName("head")[0].appendChild(a)
        }

        function c() {
          return "rgb(" + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + ")"
        }

        var s = [];
        e.requestAnimationFrame = e.requestAnimationFrame || e.webkitRequestAnimationFrame || e.mozRequestAnimationFrame || e.oRequestAnimationFrame || e.msRequestAnimationFrame || function (e) {
          setTimeout(e, 1e3 / 60)
        }, i(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"), n(), r()
      }(window, document);
    </script>
  











  

  

  

  

  

  
    <!-- cnzz Analytics -->
    <script defer src="//s4.cnzz.com/z_stat.php?id=1278280985&show=pic"
            type="text/javascript"></script>
  





</body>
</html>
